<?
include "../conf/db_connect.php";
if(!$login->logged_in && $_SESSION['date']['isAdmin'] != 1){
	header("Location: ".$CS."admin/");
}

if($_GET['dir'] == "down"){
	mysql_query("update categorii set ordine = '{$_GET['order']}' where ordine = '".($_GET['order']+1)."' and peHome = 1");
	mysql_query("update categorii set ordine = '".($_GET['order']+1)."' where id = '".$_GET['id']."'");
	header("Location: editeaza_meniu.php");
}

if($_GET['dir'] == "up"){
	mysql_query("update categorii set ordine = '{$_GET['order']}' where ordine = '".($_GET['order']-1)."' and peHome = 1");
	mysql_query("update categorii set ordine = '".($_GET['order']-1)."' where id = '".$_GET['id']."'");
	header("Location: editeaza_meniu.php");
}

if(isset($_POST['Adauga'])){
	mysql_query("update categorii set peHome='1', ordine = '{$_POST['maxOrder']}' where id = '{$_POST['categorie_id']}'") or die(mysql_error());
}

if(isset($_GET['del'])){
	mysql_query("update categorii set peHome=0, ordine = 0 where id = '{$_GET['del']}'");
	header("Location: editeaza_meniu.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/adminul.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Diete 4U  - Admin Area</title>
<!-- InstanceEndEditable -->
<link href="../style_admin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {font-size: 18px}
.style2 {color: #FFFFFF}
-->
</style>
<script src="../js.js.php"></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="../style_admin.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td height="70" background="images/bg_sus.jpg"><img src="../logo_mic.jpg" width="141" height="59" align="absmiddle" /><span class="style1">Zona de administrare </span>
      <?
	if($login->logged_in && $_SESSION['date']['isAdmin'] == 1){
	?>
	  <div style="position:absolute; width:250px; text-align:right; height:25px; right:0; top:0; background-color:#333333; color:#FFFFFF; padding-right:20px; padding-top:4px;">
	Welcome <?=$_SESSION['date']['nume']." ".$_SESSION['date']['prenume']?>! | <a style="color:#00FFFF" href="<?=$CS?>admin/logout.php">Logout</a>
	</div>
	<?
	}
	?>
	</td>
  </tr>
  <?
  if($login->logged_in && $_SESSION['date']['isAdmin'] == 1){
  ?>
  <tr>
    <td><table width="100%" border="0" cellpadding="4" cellspacing="2">
      <tr>
        <td align="center" bgcolor="#333333"><a href="<?=$CS?>"><strong>Home</strong></a></td>
        <td align="center" bgcolor="#333333"><a href="articole.php"><strong>Articole</strong></a></td>
        <td align="center" bgcolor="#333333"><a href="categorii.php"><strong>Categorii</strong></a></td>
        <td align="center" bgcolor="#333333"><a href="pagini.php"><strong>Pagini statice </strong></a></td>
        <td align="center" bgcolor="#333333"><a href="membri.php"><strong>Membri</strong></a></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td><div align="left" style="padding:15px;"><!-- InstanceBeginEditable name="Centru" -->
      <h1 align="center">Editeaza meniu site</h1>
      <p align="center"><a href="categorii.php">Inapoi la categorii </a></p>
      <div align="center">
      <form id="form2" name="form2" method="post" action="editeaza_meniu.php">
        <strong>Adauga o noua categorie in meniu:<br />
        <br />
        <select name="categorie_id" id="categorie_id">
        <?
		$sql = "select * from categorii where peHome != 1 order by nume";
		$res = mysql_query($sql);
		while($c = mysql_fetch_array($res)){
			?>
            <option value="<?=$c['id']?>"><?=$c['nume']?></option>
            <?
		}
		?>
        </select>
        </strong>
        <input name="maxOrder" type="hidden" value="<?=(@mysql_result(mysql_query("select ordine from categorii where peHome = '1' order by ordine desc limit 0,1"),0)+1)?>" /><br />
        <br />
        <input name="Adauga" type="submit" class="buton" id="Adauga" value="Adauga" />
      </form>
      </div>
      <p style="padding-left:50px;"><strong>Meniu:</strong>
        <br />
        <?
		$sql = "select * from categorii where peHome = 1 order by ordine";
		$re = mysql_query($sql);
		$i=0;
		$total = mysql_num_rows($re);
		while($m = mysql_fetch_array($re)){
			$i++;
			mysql_query("update categorii set ordine = '$i' where id = '{$m['id']}'");
			echo $m['nume']." | ";
			if($i<$total){
				echo ' <a href="editeaza_meniu.php?id='.$m['id'].'&dir=down&order='.$m['ordine'].'"><img align="absmiddle" src="down_arrow.gif" border="0"></a>';
			}
			if($i>1){
				echo ' <a href="editeaza_meniu.php?id='.$m['id'].'&dir=up&order='.$m['ordine'].'"><img align="absmiddle" src="up_arrow.gif" border="0"></a>';
			}
			echo ' <a href="editeaza_meniu.php?del='.$m['id'].'" onclick="return confirm(\'Elimini aceasta categorie din meniu?\')"><img align="absmiddle" src="remove.png" border="0"></a><br /><br />';
		}
		?>
      </p>
      <p align="center">&nbsp;</p>
    <!-- InstanceEndEditable --></div></td>
  </tr>
  <?
  }else{
  ?>
  <tr>
    <td><div align="left" style="padding:15px;">
	<?
	if(isset($_POST['login']) && $_SESSION['date']['isAdmin'] != 1){
	$login->logout();
	?>
	<div class="mesaj_not_ok" align="center">Bad email and password. </div>
	<?
	}
	?>
      <form id="form1" name="form1" method="post" action="<?=$CS?>admin/">
        <p>Please login if you want to access this section.</p>
        <p><strong>User:</strong></p>
        <p>
          <input name="username" type="text" id="username" /> 
            <input name="login" type="hidden" id="login" value="asdasdas" />
        </p>
        <p><strong>Parola:</strong></p>
        <p>
          <input name="password" type="password" id="password" />
        </p>
        <p>
          <input name="Submit" type="submit" class="buton" value="Login" />
        </p>
      </form>
      </div></td>
  </tr>
  <?
  }
  ?>
  <tr>
    <td height="30" align="center" bgcolor="#333333"><span class="style2">Copyright &copy; 2009 Diete4u.com </span></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>
